﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class web_pages_ajax_san_chitiet_ntv : System.Web.UI.Page
{
    Common _common = null;
    public string mess = "";
    public string idGui = "", idNhan = "", type = "0", idLuu = "";
    public Boolean chophepgui = false;
    public string masan = "";
    public string maNTV = "";
    public string maNTD = "";
    NhaTuyenDungCommon NTDComm = new NhaTuyenDungCommon();
    protected void Page_Load(object sender, EventArgs e)
    {
        _common = new Common();
        if (Request.Params["id"] != null)
        {
            LoadNtvDetail(Request.Params["id"].ToString());
            if (Session["SanNTD"] == null || !(Boolean.Parse(Session["SanNTD"].ToString()))) chophepgui = false;
            else { chophepgui = true;  }

            if (chophepgui) {
                masan = Session["SanNTDmasan"].ToString();
                maNTD = NTDComm.getMaNTD(Session["SanNTDuser"].ToString());
                maNTV = idNhan;
            }    
        }
    }
    void LoadNtvDetail(string id)
    {
        string _sql = "select * from NguoiTimViec_ho_so where ma_ho_so = '" + id + "'";
        DataSet _ds = _common.ExeceuteDataset(_sql);
        if (_ds.Tables[0].Rows.Count > 0)
        {
            if (LoadNguoitimviec(_ds.Tables[0].Rows[0]["ma_nguoi"].ToString()))
            {
                idNhan = _ds.Tables[0].Rows[0]["ma_nguoi"].ToString();
                idLuu = _ds.Tables[0].Rows[0]["ma_nguoi"].ToString() + "_" + _ds.Tables[0].Rows[0]["ma_ho_so"].ToString(); ;

                LoadChucvu(_ds.Tables[0].Rows[0]["ma_ho_so"].ToString());
                LoadGiolam(_ds.Tables[0].Rows[0]["ma_ho_so"].ToString());
                LoadHinhthuCty(_ds.Tables[0].Rows[0]["ma_ho_so"].ToString());
                LoadChucdanh(_ds.Tables[0].Rows[0]["ma_ho_so"].ToString());
                LoadHocvan(_ds.Tables[0].Rows[0]["ma_nguoi"].ToString());
                LoadNghiepvu(_ds.Tables[0].Rows[0]["ma_nguoi"].ToString());
                LoadNoilamviec(_ds.Tables[0].Rows[0]["ma_ho_so"].ToString());
                LoadKynangmem(_ds.Tables[0].Rows[0]["ma_nguoi"].ToString());
                LoadViecdalam(_ds.Tables[0].Rows[0]["ma_nguoi"].ToString());
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }
    }
    bool LoadNguoitimviec(string ma_ntv)
    {
        DataSet _ds_ntv = _common.ExeceuteDataset("select * from ConNguoi_nguoi where ma_nguoi = '" + ma_ntv + "'");
        if (_ds_ntv.Tables[0].Rows.Count > 0)
        {
            if ((bool)_ds_ntv.Tables[0].Rows[0]["kich_hoat"])
            {
                lbl_ma_uv.Text = _ds_ntv.Tables[0].Rows[0]["ma_nguoi"].ToString();
                lbl_cannang.Text = _ds_ntv.Tables[0].Rows[0]["can_nang"].ToString() + " (kg)";
                lbl_chieucao.Text = _ds_ntv.Tables[0].Rows[0]["chieu_cao"].ToString() + " (cm)";
                lbl_diachi.Text = (bool)_ds_ntv.Tables[0].Rows[0]["ht_diachi"] == true ? _ds_ntv.Tables[0].Rows[0]["dia_chi_chi_tiet"].ToString() + " " + _common.execScalar("select dbo.fcGetDiaChiChiTiet ('" + _ds_ntv.Tables[0].Rows[0]["dia_chi"].ToString() + "')") : "Liên hệ với trung tâm";
                lbl_dienthoai.Text = (bool)_ds_ntv.Tables[0].Rows[0]["ht_dienthoai"] == true ? _ds_ntv.Tables[0].Rows[0]["dien_thoai_di_dong"].ToString() : "Liên hệ với trung tâm";
                lbl_email.Text = (bool)_ds_ntv.Tables[0].Rows[0]["ht_email"] == true ? _ds_ntv.Tables[0].Rows[0]["email"].ToString() : "Liên hệ với trung tâm";
                lbl_goitinh.Text = (bool)_ds_ntv.Tables[0].Rows[0]["gioi_tinh"] == true ? "Nam" : "Nữ";
                lbl_honnhan.Text = (bool)_ds_ntv.Tables[0].Rows[0]["hon_nhan"] == true ? "Đã có gia đình" : "Chưa có gia đình";
                lbl_ngaysinh.Text = Convert.ToDateTime(_ds_ntv.Tables[0].Rows[0]["ngay_sinh"].ToString()).ToString("dd/MM/yyyy");
                lbl_ten_uv.Text = _ds_ntv.Tables[0].Rows[0]["ho_ten"].ToString();

            }
            else return false;
        }
        return true;
    }
    void LoadViecdalam(string ma)
    {
        DataSet _ds_ = _common.ExeceuteDataset("select * from NguoiTimViec_kinh_nghiem_lam_viec as A inner join DanhMuc_chuc_danh as B on A.ma_chuc_danh = B.ma_chuc_danh where A.ma_nguoi ='" + ma + "'");
        if (_ds_.Tables[0].Rows.Count > 0)
        {
            lbl_viec_dalam.Text += "Tên công ty : " + _ds_.Tables[0].Rows[0]["ten_cong_ty"].ToString() + " <br />";
            lbl_viec_dalam.Text += "Chức danh : " + _ds_.Tables[0].Rows[0]["ten_chuc_danh"].ToString() + " <br />";
            lbl_viec_dalam.Text += "Kinh nghiệm : " + _ds_.Tables[0].Rows[0]["kinh_nghiem"].ToString() + " <br />";
            lbl_viec_dalam.Text += "Mức lương : " + _ds_.Tables[0].Rows[0]["muc_luong"].ToString();
        }
    }
    void LoadKynangmem(string ma)
    {
        DataSet _ds_ = _common.ExeceuteDataset("select * from ConNguoi_kha_nang_mem as A inner join DanhMuc_kha_nang_mem as B on A.ma_kn_mem = B.ma_kn_mem where A.ma_nguoi ='" + ma + "'");
        if (_ds_.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < _ds_.Tables[0].Rows.Count; i++)
            {
                lbl_kynang_mem.Text += _ds_.Tables[0].Rows[0]["ten_kn_mem"].ToString() + " <br />";
            }
        }
    }
    void LoadNoilamviec(string ma)
    {
        DataSet _ds_ = _common.ExeceuteDataset("select * from NguoiTimViec_thanh_pho_lam_viec as A inner join DanhMuc_dia_chi as B on A.ma_dia_chi = B.ma_dia_chi where A.ma_ho_so ='" + ma + "'");
        if (_ds_.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < _ds_.Tables[0].Rows.Count; i++)
            {
                lbl_nguyenvong_noilamviec.Text += _ds_.Tables[0].Rows[0]["ten_dia_chi"].ToString() + " <br />";
            }
        }
    }
    void LoadNghiepvu(string ma)
    {
        DataSet _ds_ = _common.ExeceuteDataset("select * from ConNguoi_nghiep_vu as A inner join DanhMuc_nghiep_vu as B on A.ma_nghiep_vu = B.ma_nghiep_vu where A.ma_nguoi ='" + ma + "'");
        if (_ds_.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < _ds_.Tables[0].Rows.Count; i++)
            {
                if ((bool)_ds_.Tables[0].Rows[i]["ngoai_ngu"])
                {
                    lbl_chuyenmon_ngoaingu.Text = _ds_.Tables[0].Rows[i]["ten_nghiep_vu"].ToString() + " (kinh nghiệm " + _ds_.Tables[0].Rows[i]["kinh_nghiem"].ToString() + " tháng)";
                }
                if ((bool)_ds_.Tables[0].Rows[i]["tin_hoc"])
                {
                    lbl_chuyenmon_tinhoc.Text = _ds_.Tables[0].Rows[i]["ten_nghiep_vu"].ToString() + " (kinh nghiệm " + _ds_.Tables[0].Rows[i]["kinh_nghiem"].ToString() + " tháng)";
                }
            }
        }
    }
    void LoadHocvan(string ma)
    {
        DataSet _ds_ = _common.ExeceuteDataset("select * from ConNguoi_hoc_van_chuyen_mon as A inner join DanhMuc_hoc_van as B on A.ma_hoc_van = B.ma_hoc_van inner join DanhMuc_chuyen_mon as C on A.ma_chuyen_mon = C.ma_chuyen_mon where A.ma_nguoi ='" + ma + "'");
        if (_ds_.Tables[0].Rows.Count > 0)
        {
            lbl_chuyenmon_hocvan.Text = _ds_.Tables[0].Rows[0]["ten_hoc_van"].ToString();
            lbl_chuyenmon_nganhnghe.Text = _ds_.Tables[0].Rows[0]["ten_chuyen_mon"].ToString();
        }
    }
    void LoadChucdanh(string ma)
    {
        DataSet _ds_ = _common.ExeceuteDataset("select * from NguoiTimViec_ho_so as A inner join DanhMuc_chuc_danh as B on A.chuc_danh_mong_muon" +
            " = B.ma_chuc_danh where ma_ho_so = '" + ma + "'");
        if (_ds_.Tables[0].Rows.Count > 0)
        {
            lbl_nguyenvong_chucdanh.Text = _ds_.Tables[0].Rows[0]["ten_chuc_danh"].ToString();
            lbl_nguyenvong_mucluong.Text = _ds_.Tables[0].Rows[0]["muc_luong_mong_muon"].ToString() + " (đồng)";
        }
    }
    void LoadHinhthuCty(string ma)
    {
        DataSet _ds_ = _common.ExeceuteDataset("select * from NguoiTimViec_qui_mo_cong_ty as A inner join DanhMuc_so_huu as B on A.ma_so_huu = B.ma_so_huu where A.ma_ho_so ='" + ma + "'");
        if (_ds_.Tables[0].Rows.Count > 0)
            lbl_nguyenvong_hinhthuc_cty.Text = _ds_.Tables[0].Rows[0]["ten_so_huu"].ToString();
    }
    void LoadChucvu(string ma)
    {
        DataSet _ds_ = _common.ExeceuteDataset("select * from NguoiTimViec_mong_muon_chuyen_mon as A inner join DanhMuc_chuyen_mon as B on A.ma_chuyen_mon = B.ma_chuyen_mon where A.ma_ho_so ='" + ma + "'");
        if (_ds_.Tables[0].Rows.Count > 0)
            lbl_nguyenvong_chucvu.Text = _ds_.Tables[0].Rows[0]["ten_chuyen_mon"].ToString();
    }
    void LoadGiolam(string ma)
    {
        DataSet _ds_ = _common.ExeceuteDataset("select * from NguoiTimViec_thoi_gian_lam_viec as A inner join DanhMuc_thoi_gian_lam_viec as B on A.ma_thoi_gian_lv = B.ma_thoi_gian_lv where A.ma_ho_so ='" + ma + "'");
        if (_ds_.Tables[0].Rows.Count > 0)
            lbl_nguyenvong_giolam.Text = _ds_.Tables[0].Rows[0]["ten_thoi_gian_lv"].ToString();
    }
}
